package ai.text.impl.extractor;

import ai.graph.GraphConstants;
import opennlp.tools.parser.Parse;
import opennlp.tools.parser.ParserME;
import opennlp.tools.util.Span;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.Vertex;
import edu.uci.ics.jung.graph.impl.DirectedSparseEdge;
import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
import edu.uci.ics.jung.utils.UserData;

public class ExtractorEngine {

	private Graph g;

	public void buildGraph(Parse pp, Vertex parent) {
		Vertex current = g.addVertex(new DirectedSparseVertex());
		if (parent != null) {
			g.addEdge(new DirectedSparseEdge(parent, current));
		}

		int start;
		start = pp.getSpan().getStart();
		if (!pp.getType().equals(ParserME.TOK_NODE)) {
			current.setUserDatum(GraphConstants.TYPE, pp.getType(),
					UserData.SHARED);
		}
		StringBuffer sb = new StringBuffer();
		for (Parse c : pp.getChildren()) {
			Span s = c.getSpan();
			if (start < s.getStart()) {
				// System.out.println("pre "+start+" "+s.getStart());
				// sb.append(pp.getText().substring(start, s.getStart()));
			}
			buildGraph(c, current);
			start = s.getEnd();
		}
		Span s = pp.getSpan();
		// sb.append(pp.getText().substring(start, pp.getSpan().getEnd()));
		sb.append(pp.getText().substring(s.getStart(), s.getEnd()));
		current.setUserDatum(GraphConstants.NAME, sb.toString(),
				UserData.SHARED);
	}

	/**
	 * Extract data from : simple declarative clause, i.e. one that is not
	 * introduced by a (possible empty) subordinating conjunction or a wh-word
	 * and that does not exhibit subject-verb inversion.
	 * 
	 */
	public void extractS(Parse p) {
		
	}
	
	/*
	 * Noun phrase
	 */
	public void extractNP(Parse p) {
		
	}
	
	/*
	 * Verb phrase
	 */
	public void extractVP(Parse p) {
		
	}
}
